﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ADO;
using Service.Employee;

public partial class ManageUserInfo : System.Web.UI.Page
{
    int oldid;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //bindGrid();
            GridView1.DataBind();
        }
    }

    private void bindGrid()
    {
        string connString = "Data Source=localhost;Initial Catalog=webinf;Integrated Security=SSPI;";
        DataBaseAccess dbs = new DataBaseAccess(connString);
        String Sqlstring = "select * from Staff";
        //string Sqlstring2 = "select * from Customers";
        DataTable myds = dbs.GetDataTable(Sqlstring);
        //DataSet myds1 = dbs.GetDataSet(Sqlstring2);
        GridView1.DataSource = myds;
        GridView1.DataBind();
        //GridView2.DataSource = myds1;
        //GridView2.DataBind();
    }

    //员工表修改更新
    protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
    {
        
        //int oldStaffID = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);//int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
        //int newStaffID = 0;
        //newStaffID = oldStaffID;
        //string name = e.NewValues["Name"].ToString();
        //string department = e.NewValues["Department"].ToString();
        //string email = e.NewValues["Email"].ToString();
        //string psw = e.NewValues["Psw"].ToString();

        GridView1.EditIndex = -1;
        //bindGrid();
        GridView1.DataBind();


    }
    //员工表的编辑
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 
    {
        //oldid = int.Parse(GridView1.Rows[e.NewEditIndex].Cells[0].Text);//取id
        //Session["oldid"] = int.Parse(GridView1.Rows[e.NewEditIndex].Cells[0].Text);
        GridView1.EditIndex = e.NewEditIndex;
        //bindGrid();

    }
    //员工表取消编辑
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        //bindGrid();
    }
    //员工表删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int staffid = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
        EmployeesControl ec = new EmployeesControl();
        ec.delete(staffid);
        //bindGrid();

    }
    //员工信息增添
    protected void AddButton_Click(object sender, EventArgs e)
    {
        StaffAllSqlSource.Insert();
        GridView1.DataBind();
    }
    





  
}
